export class Card {
    constructor(config) {
        this.id = config.id || Math.random().toString(36).substr(2, 9);
        this.name = config.name || 'Unknown Card';
        this.type = config.type || 'attack'; // attack, skill, power
        this.rarity = config.rarity || 'common'; // common, uncommon, rare
        this.cost = config.cost !== undefined ? config.cost : 1;
        this.description = config.description || '';
        this.damage = config.damage || 0;
        this.block = config.block || 0;
        this.effects = config.effects || [];
        this.upgraded = config.upgraded || false;
    }

    play(target, source) {
        // 基本卡牌效果实现
        if (this.damage > 0 && target) {
            target.takeDamage(this.damage);
        }

        if (this.block > 0 && source) {
            source.addBlock(this.block);
        }

        // 执行其他效果
        this.applyEffects(target, source);

        return true;
    }

    applyEffects(target, source) {
        // 应用卡牌效果
        for (const effect of this.effects) {
            switch (effect.type) {
                case 'draw':
                    source.drawCards(effect.amount);
                    break;
                case 'vulnerable':
                    target.addStatus('vulnerable', effect.amount);
                    break;
                case 'weak':
                    target.addStatus('weak', effect.amount);
                    break;
                case 'strength':
                    source.addStatus('strength', effect.amount);
                    break;
                // 更多效果类型...
            }
        }
    }

    upgrade() {
        if (this.upgraded) return false;
        
        // 默认升级逻辑
        if (this.damage > 0) this.damage += 3;
        if (this.block > 0) this.block += 3;
        
        this.upgraded = true;
        this.name = this.name + '+';
        
        return true;
    }

    getCardData() {
        return {
            id: this.id,
            name: this.name,
            type: this.type,
            rarity: this.rarity,
            cost: this.cost,
            description: this.description,
            damage: this.damage,
            block: this.block,
            effects: this.effects,
            upgraded: this.upgraded
        };
    }
}